
package com.borqs.music.tasks;

import static com.borqs.music.http.RequestMethod.GET;
import static com.borqs.music.util.MusicConf.ReqParam.COUNT;
import static com.borqs.music.util.MusicConf.ReqParam.USERID;
import static com.borqs.music.util.MusicConf.ReqParam.ISFULL;
import static com.borqs.music.util.MusicConf.ReqParam.PAGE;
import static com.borqs.music.util.MusicConf.ReqType.MUSIC_SONG_OF_USER;

import java.util.HashMap;
import java.util.Map;

import com.borqs.music.executor.TaskListener;
import com.borqs.music.http.HttpRequest;
import com.borqs.music.util.MusicConf;

public class GetSongsTask extends SongTask {

    // set to Integer.MAX_VALUE try to get all private songs.
    public static final int ALL_COUNT = Integer.MAX_VALUE;

    private int mPage;
    private String mTicket;
    private int mDefault;
    private long mUserId = -1;
    private String mFileType = "";

    public GetSongsTask(TaskListener listener, String ticket) {
        super(listener, false);
        mTicket = ticket;
        mDefault = ALL_COUNT;
        mPage = 0;
    }

    public GetSongsTask(TaskListener listener, String ticket, int page, boolean isFull) {
        super(listener, isFull);
        mTicket = ticket;
        mPage = page;
        mDefault = PAGE_COUNT;
    }

    public GetSongsTask(TaskListener listener, String ticket, long uid, int page) {
        super(listener, false);
        mTicket = ticket;
        mUserId = uid;
        mPage = page;
        mDefault = PAGE_COUNT;
    }
    
    public void setFileType(String fileType){
        mFileType = fileType;
    }

    @Override
    public HttpRequest prepareRequest() {
        Map<String, String> params = new HashMap<String, String>();
        params.put(PAGE, String.valueOf(mPage));
        if (mUserId > 0) {
            params.put(USERID, String.valueOf(mUserId));
        }
        params.put(COUNT, String.valueOf(mDefault));
        params.put(ISFULL, String.valueOf(isFull()));

        if (mFileType != null) {
            params.put("filetype", mFileType);
        }

        
        String url = MusicConf.getUrl(MUSIC_SONG_OF_USER);
        HttpRequest req = new HttpRequest(GET, url, mTicket, params);
        return req;
    }
}
